﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WeifenLuo.WinFormsUI.Docking;

namespace Bing.Studio
{
    public delegate void NotificationHandler(object sender, NotificationEventArgs e);

    public class BaseForm : DockContent
    {
        public event NotificationHandler NotificationEvent;

        protected void SendNotification(string msg)
        {
            if (NotificationEvent != null)
            {
                NotificationEvent(this, new NotificationEventArgs(msg));
            }
        }

        protected void SendNotification(Exception ex)
        {
            if (NotificationEvent != null)
            {
                StringBuilder strbuilder = new StringBuilder();
                strbuilder.Append("\r\n************************ 异常信息 ************************");
                strbuilder.Append(ex.Message);
                strbuilder.Append("\r\n");
                strbuilder.Append(ex.StackTrace);
                strbuilder.Append("\r\n**********************************************************");
                NotificationEvent(this, new NotificationEventArgs(strbuilder.ToString()));
            }
        }
    }

    public class NotificationEventArgs : EventArgs
    {
        public string Message { get; private set; }

        public NotificationEventArgs(string msg)
        {
            Message = msg;
        }
    }
}
